using System;
using System.Collections.Generic;

namespace Is
{
    public abstract class IsBase<T, TTarget> : IIs<TTarget> where T : IsBase<T, TTarget>
    {
        protected TTarget target;
        protected bool negate;

        protected IsBase(TTarget target, bool negate)
        {
            this.target = target;
            this.negate = negate;
        }

        public TTarget Target
        {
            get { return target; }
        }

        public bool Negate
        {
            get { return negate; }
        }

        bool IIs<TTarget>.Apply(Func<TTarget, bool> positiveCase, Func<TTarget, bool> negativeCase)
        {
            return negate 
                ? negativeCase(target) 
                : positiveCase(target);
        }

        public bool Equal(TTarget expected)
        {
            return ((IIs<TTarget>)this).Apply(
                t => Core.Is.Equal(t, expected),
                t => Core.Is.NotEqual(t, expected));
        }

        public bool Equal(TTarget expected, IEqualityComparer<TTarget> comparer)
        {
            return ((IIs<TTarget>)this).Apply(
                t => Core.Is.Equal(t, expected, comparer),
                t => Core.Is.NotEqual(t, expected, comparer));
        }
    }
}